package commoditymanagement;

import static org.junit.Assert.fail;

import java.math.BigDecimal;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class CommodityDaoImplTest {

	CommodityDao dao = new CommodityDaoImpl();
	
	@Before  // 前置条件
	public void testInsert() {
		Commodity c1 = new Commodity(1, "袜子", CommodityType.CLOTH, BigDecimal.valueOf(9.9), 100);
		Commodity c2 = new Commodity(2, "小风扇", CommodityType.ELECTRIC, BigDecimal.valueOf(29.9), 200);
		Commodity c3 = new Commodity(3, "乌龙茶", CommodityType.DRINK, BigDecimal.valueOf(3.5), 900);
		Commodity c4 = new Commodity(4, "卫龙辣条", CommodityType.FOOD, BigDecimal.valueOf(3.9), 400);
		Commodity c5 = new Commodity(5, "小衬衫", CommodityType.CLOTH, BigDecimal.valueOf(89.9), 50);
		Commodity c6 = new Commodity(6, "茉莉花茶", CommodityType.DRINK, BigDecimal.valueOf(4.6), 100);
		
		dao.insert(c1);
		dao.insert(c2);
		dao.insert(c3);
		dao.insert(c4);
		dao.insert(c5);
		dao.insert(c6);
	}

	@Test
	public void testRemove() {
		boolean remove = dao.remove(2);
	}

	@Test
	public void testUpdate() {
		Commodity c4 = new Commodity(4, "卫龙辣条条", CommodityType.FOOD, BigDecimal.valueOf(9.9), 40);
		dao.update(c4);
	}

	@Test
	public void testSelectById() {
		Commodity c = dao.selectById(11);
		System.out.println(c);
	}

	@Test
	public void testSelectByPrice() {
		List<Commodity> cs = dao.selectByPrice(BigDecimal.valueOf(3), BigDecimal.valueOf(10));
		cs.forEach(System.out::println);
	}

	@After  	// 后置条件
	public void testSelectAll() {
		System.out.println("--------------------------");
		dao.selectAll().forEach(System.out::println);
		System.out.println("--------------------------");
	}

	@Test
	public void testSelectByName() {
		List<Commodity> cs = dao.selectByName("小");
		cs.forEach(System.out::println);
	}

	@Test
	public void testSelectByType() {
		List<Commodity> cs = dao.selectByType(CommodityType.DRINK);
		cs.forEach(System.out::println);
	}

}
